<template>
    <dept-user-select :visible="visible" @afterSelect="saveCandidate" @cancel="userSelectCancel">
        <template slot="form">
            <el-form ref="form" :model="form">
                <el-form-item label="转办意见">
                    <el-input type="textarea" :rows="3" placeholder="请输入转办意见" v-model="form.opinion"></el-input>
                </el-form-item>
            </el-form>
        </template>
    </dept-user-select>
</template>

<script>
    import {addCandidate} from "@/api/opinion";

    export default {
        name: "candidateManage",
        data() {
            return {
                form:{},
            }
        },
        props: {
            targetId: Number,
//            targetId: {
//                type: Number,
//                required: true
//            },
            visible: {
                type: Boolean,
                default: false
            },
            afterClose: {
                type: Function
            },
        },
        methods:{
            userSelectCancel(){
                this.visible = false;
                this.afterClose();
            },
            saveCandidate(userIds) {
                if (userIds == null || userIds.length == 0) {
                    this.$notify({
                        title: "提示",
                        message: "请选择转办用户",
                        type: "warn",
                        duration: 2000
                    });
                    return false;
                }
                let data = {
                    targetId: this.targetId,
                    userIds: userIds,
                    opinion: this.form.opinion
                };
                this.$confirm("确定转办吗?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(() => {
                    addCandidate(data)
                        .then((res) => {
                            this.$notify({
                                title: "成功",
                                message: "转办成功",
                                type: "success",
                                duration: 2000
                            });
                            this.userSelectCancel();
                        });
                })
            },
        }
    }
</script>

<style scoped>

</style>
